﻿/*
 * 安特威D_Country表操作类
 * Lyf@ZD_20160326
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataControl;
using System.Data;
using System.Text;

namespace ATW.MT.BUS
{
    public class bus_D_Country
    {
        DataAccess da = null;
        public bus_D_Country()
        {
            da = new DataAccess();
        }
        #region 方法
        //查
        public DataTable Country(string name, string strCode, string strAbbr, int page, int pagesize)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append(@"select dcuDesc,DCUID,CountryCode,CountryAbbr,L.LanName from D_Country C
                            left join D_Language L on L.LanId=C.CountryLan
                            where C.RowStatus=1");
            if (name != "")
            {
                sql.Append(" and dcuDesc like '%" + name + "%'");
            }
            if (strCode != "")
            {
                sql.Append(" and CountryCode like '%" + strCode + "%'");
            }
            if (strAbbr != "")
            {
                sql.Append(" and CountryAbbr like '%" + strAbbr + "%'");
            }
            return da.PageSize(sql.ToString(), page, pagesize, "DCUID");
        }
        //增
        public int AddItem(string Desc, int intCode, string strAbbr)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into D_Country(dcuDesc,CountryCode,CountryAbbr,RowStatus,CreatedDate) values('{0}',{1},'{2}','1',getdate())",
                Desc, intCode, strAbbr);
            return da.ExcuteNoQuery(sql.ToString());
        }
        /// <summary>
        /// 新增国家
        /// </summary>
        /// <param name="Desc"></param>
        /// <param name="intCode"></param>
        /// <param name="strAbbr"></param>
        /// <param name="landid"></param>
        /// <returns></returns>
        public int AddItem(string Desc, int intCode, string strAbbr, string landid)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into D_Country(dcuDesc,CountryCode,CountryAbbr,CountryLan,RowStatus,CreatedDate) values('{0}',{1},'{2}','{3}','1',getdate())",
                Desc, intCode, strAbbr, landid);
            return da.ExcuteNoQuery(sql.ToString());
        }
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public bool isCountryExist(string name)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select * from D_Country where dcuDesc='{0}' and rowstatus<>'2'", name);
            DataTable dt = da.ExecuteDataTable(sql.ToString());
            if (dt != null && dt.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        public DataTable getLanList()
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select * from D_Language");
            return da.ExecuteDataTable(sql.ToString());
        }
        //删
        public int CountryChangeStatus(string strId, string strStatus)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"update D_Country set RowStatus='" + strStatus + "' where DCUID='" + strId + "'");
            return da.ExcuteNoQuery(sql.ToString());
        }


        #endregion
    }
}